package com.itheima.listenter;

import com.itheima.domain.db.Log;
import com.itheima.feign.DbServiceFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class LogListenter {

    @Autowired
    private DbServiceFeign dbServiceFeign;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "tanhua.queue"),
            exchange = @Exchange(name = "tanhua.topic", type = ExchangeTypes.TOPIC),
            key = "log"
    ))
    public void logListenter(Log log) {
        System.out.println( "接受到消息"+log );
        dbServiceFeign.save(log);
    }
}
